/**
 * 
 */





OrderPage = {
		'BindEvent': function(){
			$('#btnSubmit').bind('click', function(){
				var thirdOrderId = $('#thirdOrderId').val();
				var orderId = $('#orderId').val();
				var reveiverAdd = $('#reveiverAdd').val();
				var orderStartDate =$('#orderStartDate').val();
				var orderEndDate = $('#orderEndDate').val();
				var orderEndTime = $('#orderEndTime').val();
				var orderEndTimeEnd=$('#orderEndTimeEnd').val();
				var orderStatus = $('#orderStatus').val();
				var invoiceDate = $('#invoiceDate').val();
				//是否有返现
				var cashBackStatus = $('#cash_back_status').val();
				//是否有返现
				var invoiceKind = $('#invoiceKind').val();
				//是否有返现
				var invoiceStatus = $('#invoiceStatus').val();
				// 存在留言
				var message = document.getElementById("buyer_message").checked;
				var receiverMobile = $('#consignee_cellphone').val();
				var consigneeName = $('#consignee_name').val();
				var orderType = $('#orderType').val();
				function _successFun(result){
					if(result.IsSuccess == 0){
						alert(result.ErrorMsg);
					}
					OrderPage.BindTable(result.Result);
				}
				var result = OrderService.Order(thirdOrderId,
						receiverMobile,
						orderId,
						reveiverAdd,
						orderStartDate,
						orderEndDate,orderStatus, cashBackStatus,invoiceKind,invoiceStatus,consigneeName,message,
						orderType,invoiceDate,orderEndTime,orderEndTimeEnd,1,20,_successFun);
			});
			
			$('#exportExcel').bind('click', function(){
				var thirdOrderId = $('#thirdOrderId').val();
				var receiverMobile = $('#consignee_cellphone').val();
				var orderId = $('#orderId').val();
				var reveiverAdd = $('#reveiverAdd').val();
				var orderStartDate =$('#orderStartDate').val();
				var orderEndDate = $('#orderEndDate').val();
				var orderStatus = $('#orderStatus').val();
				var consigneeName = $('#consignee_name').val();

				//是否有返现
				var cashBackStatus = $('#cash_back_status').val();
				//是否有返现
				var invoiceKind = $('#invoiceKind').val();
				var orderType = $('#orderType').val();
				var invoiceDate = $('#invoiceDate').val();
				var orderEndTime = $('#orderEndTime').val();
				var orderEndTimeEnd=$('#orderEndTimeEnd').val();

				
				if(invoiceKind==''){
					alert('未选择发票类型');
					return ;
				}
				var invoiceStatus = $('#invoiceStatus').val();
				
				// 存在留言
				var message = document.getElementById("buyer_message").checked;
				
				var params = 'thirdOrderId=' + thirdOrderId ;
				params += '&orderId='+orderId;
				params += '&reveiverAdd='+reveiverAdd;
				params += '&orderStartDate='+orderStartDate;
				params += '&orderEndDate='+orderEndDate;
				params += '&orderStatus='+orderStatus;
				params += '&cashBackStatus='+cashBackStatus;
				params += '&invoiceKind='+invoiceKind;
				params += '&invoiceStatus='+invoiceStatus;
				params += '&message='+message;
				params += '&consigneeName='+consigneeName;
				params += '&receiverMobile='+receiverMobile;
				params += '&orderType='+orderType;
				params += '&invoiceDate='+invoiceDate;
				params += '&orderEndTime='+orderEndTime;
				params += '&orderEndTimeEnd='+orderEndTimeEnd;
				var url = '/order/orderexport?' + params;
				window.open(url);
			 });
			$('#orderInfoexportExcel').bind('click', function(){
				var thirdOrderId = $('#thirdOrderId').val();
				var receiverMobile = $('#consignee_cellphone').val();
				var orderId = $('#orderId').val();
				var reveiverAdd = $('#reveiverAdd').val();
				var orderStartDate =$('#orderStartDate').val();
				var orderEndDate = $('#orderEndDate').val();
				var orderStatus = $('#orderStatus').val();
				var consigneeName = $('#consignee_name').val();
				//是否有返现
				var cashBackStatus = $('#cash_back_status').val();
				//是否有返现
				var invoiceKind = $('#invoiceKind').val();
				var orderType = $('#orderType').val();
				var invoiceStatus = $('#invoiceStatus').val();
				var invoiceDate = $('#invoiceDate').val();
				var orderEndTime = $('#orderEndTime').val();
				var orderEndTimeEnd=$('#orderEndTimeEnd').val();

				// 存在留言
				var message = document.getElementById("buyer_message").checked;
				var params = 'thirdOrderId=' + thirdOrderId ;
				params += '&orderId='+orderId;
				params += '&reveiverAdd='+reveiverAdd;
				params += '&orderStartDate='+orderStartDate;
				params += '&orderEndDate='+orderEndDate;
				params += '&orderStatus='+orderStatus;
				params += '&cashBackStatus='+cashBackStatus;
				params += '&invoiceKind='+invoiceKind;
				params += '&invoiceStatus='+invoiceStatus;
				params += '&message='+message;
				params += '&consigneeName='+consigneeName;
				params += '&receiverMobile='+receiverMobile;
				params += '&orderType='+orderType;
				params += '&invoiceDate='+invoiceDate;
				params += '&orderEndTime='+orderEndTime;
				params += '&orderEndTimeEnd='+orderEndTimeEnd;

				var url = '/order/orderInfoexportExcel?' + params;
				window.open(url);
			});
		},
		'BindTable': function(result){
			lst_order_en = result.datas;
			
			var html = '';
			for(var index in lst_order_en){
				var order_en = lst_order_en[index];
				var tr_html = "<tr>";
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.third_order_id) +"<br /><a target='_blank' href='/Order/orderdetail?order_id="+ order_en.order_id +"'>" + order_en.order_id + "</a></td>";
				tr_html += "<td>" + OrderPage.ConvertOrderType(order_en.order_type) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertWhaleyStatus(order_en.order_status) + "</td>"
				tr_html += "<td> <font size='2' color='red'>" + OrderPage.ConvertInvoiceStatus(order_en.invoice_status) + "</font></td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.buyer_alipay_no) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.buyer_name) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.buyer_nick) + "</td>"
				tr_html += "<td>" +  OrderPage.ConvertStrNull(order_en.buyer_message)  + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.seller_memo) + "</td>"
				if(order_en.invoice_title !=null && order_en.invoice_title !='' &&order_en.invoice_title !=undefined){
					tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.invoice_title)  + "</td>"
				}else{
					tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.invoice_name)  + "</td>"
				}
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.invoice_amount) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.consignee_name) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.goods_amount) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.payment_amount) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.freight) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.discount_fee) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.order_amount) + "</td>"
				tr_html += "<td>" + OrderPage.ConvertStrNull(order_en.income_amount) + "</td>"
				tr_html += "<td>" + order_en.order_date + "</td>"
				tr_html += "<td>" + OrderPage.ConvertCashBackStatus(order_en.cash_back_status) + "</td>"
				tr_html += "</tr>";
				html += tr_html;
			} 
			$('#tbl_order_info tbody').html('');
			$('#tbl_order_info tbody').append(html);
			
			var ul= "<ul class=\"pager\">";
			    ul+="<li id='page_first' index='1'>";
			    ul+="<a href=\"#\"  id='page_first' index='1'>首页</a>";
			    ul+="</li>"
				ul+="<li>";
			    ul+="<a href=\"#\"  id='page_prov' index='"+result.preIndex+"'>← 上一页</a>";
			    ul+="</li>"
			    ul+="<li>";
			    ul+="<a href=\"#\" id='page_next' index='"+result.nextIndex+"'>下一页 →</a>";
			    ul+="</li>"
				ul+="<li>";
			    ul+="<a href=\"#\" id='page_last' index='"+result.totalPage+"'>尾页</a>";
			    ul+="</li>"
				ul+="<li>";
			    ul+="共"+result.totalCount+"条 共"+result.totalPage+"页 当前在第"+result.index+"页";
			    ul+="<a  href=\"#\" id='page_jump'>"+"跳转 到</a><input id='jump_Number' type=\"number\" style=\"width:50px;\">页";
			    ul+="</li>"
			    ul+= "</ul>";
			
			$('#div_pageInfo ul').html('');
			$('#div_pageInfo ul').html(ul);

			OrderPage.BindPageEvent();
		
		},
		'BindPageEvent': function(){
			
			var thirdOrderId = $('#thirdOrderId').val();
			var orderId = $('#orderId').val();
			var reveiverAdd = $('#reveiverAdd').val();
			var orderStartDate = $('#orderStartDate').val();
			var orderEndDate = $('#orderEndDate').val();
			
			var orderStatus = $('#orderStatus').val();
			
			
			//是否有返现
			var cashBackStatus = $('#cash_back_status').val();
			//是否有返现
			var invoiceKind = $('#invoiceKind').val();
			//是否有返现
			var invoiceStatus = $('#invoiceStatus').val();
			// 存在留言
			var message = document.getElementById("buyer_message").checked;
			var invoiceDate = $('#invoiceDate').val();
			var orderEndTime = $('#orderEndTime').val();
			var orderEndTimeEnd=$('#orderEndTimeEnd').val();

			var receiverMobile = $('#consignee_cellphone').val();
			var consigneeName = $('#consignee_name').val();
			var orderType = $('#orderType').val();

			var index =1;
			
			$('#page_first').bind('click', function(){
				  index = $(this).attr('index');
					var result = OrderService.Order(thirdOrderId,
							receiverMobile,
							orderId,
							reveiverAdd,
							orderStartDate,
							orderEndDate,orderStatus,cashBackStatus,invoiceKind,invoiceStatus,consigneeName,message,
							orderType,invoiceDate,orderEndTime,orderEndTimeEnd,index);
					OrderPage.BindTable(result.Result);
			});
			
			$('#page_prov').bind('click', function(){
				 index = $(this).attr('index');
					var result = OrderService.Order(thirdOrderId,
							receiverMobile,
							orderId,
							reveiverAdd,
							orderStartDate,
							orderEndDate,orderStatus,cashBackStatus,invoiceKind,invoiceStatus,consigneeName,message,
							orderType,invoiceDate,orderEndTime,orderEndTimeEnd,index);
					OrderPage.BindTable(result.Result);
			});
			
			$('#page_next').bind('click', function(){
    				 index = $(this).attr('index');
    					var result = OrderService.Order(thirdOrderId,
    							receiverMobile,
    							orderId,
    							reveiverAdd,
    							orderStartDate,
    							orderEndDate,orderStatus,cashBackStatus,invoiceKind,invoiceStatus,consigneeName,message,
    							orderType,invoiceDate,orderEndTime,orderEndTimeEnd,index);
    					OrderPage.BindTable(result.Result);
			});
			
			$('#page_last').bind('click', function(){
				 index = $(this).attr('index');
					var result = OrderService.Order(thirdOrderId,
							receiverMobile,
							orderId,
							reveiverAdd,
							orderStartDate,
							orderEndDate,orderStatus,cashBackStatus,invoiceKind,invoiceStatus,consigneeName,message,
							orderType,invoiceDate,orderEndTime,orderEndTimeEnd,index);
					OrderPage.BindTable(result.Result);
			});
			
			$('#page_jump').bind('click',function(){
				
				 index = $('#jump_Number').val();
					var result = OrderService.Order(thirdOrderId,
							receiverMobile,
							orderId,
							reveiverAdd,
							orderStartDate,
							orderEndDate,orderStatus,cashBackStatus,invoiceKind,invoiceStatus,consigneeName,message,
							orderType,invoiceDate,orderEndTime,orderEndTimeEnd,index);
					OrderPage.BindTable(result.Result);
			});
			
		},
		'ConvertStrNull':function(obj){
			
			if(obj == null){
				return '';
			}
			else{
				return obj;
			}
		},
		'ConvertStatus':function(obj){
			if(obj == 'TRADE_FINISHED'){
				return '订单完成';
			}else if(obj =='TRADE_CLOSED_BY_TAOBAO'){
				return '淘宝关闭订单';
			}else if(obj =='TRADE_CLOSED'){
				return '订单关闭';
			}else if(obj =='WAIT_SELLER_SEND_GOODS'){
				return '待发货';
			}else if(obj =='WAIT_BUYER_CONFIRM_GOODS'){
				return '待收货';
			}else if(obj =='WAIT_BUYER_PAY'){
				return '待付款';
			}
		} ,		
		'ConvertWhaleyStatus':function(obj){
			if(obj == '10'){
				return '已提交';
			}else if(obj =='11'){
				return '已审核';
			}else if(obj =='12'){
				return '订单处理中';
			}else if(obj =='21'){
				return '待支付';
			}else if(obj =='22'){
				return '已支付';
			}else if(obj =='25'){
				return '物流处理中';
			}else if(obj =='31'){
				return '已发货';
			}else if(obj =='32'){
				return '已签收';
			}else if(obj =='33'){
				return '物流处理中';
			}else if(obj =='35'){
				return '已完成';
			}else if(obj =='41'){
				return '退货中';
			}else if(obj =='42'){
				return '退货完成';
			}else if(obj =='43'){
				return '换货中';
			}else if(obj =='44'){
				return '换货完成';
			}else if(obj =='51'){
				return '用户取消';
			}else if(obj =='52'){
				return '客服取消';
			}else if(obj =='53'){
				return '系统自动取消';
			}
		} ,
		'ConvertInvoiceKind':function(obj){
			if(obj == '0'){
				return '不开发票';
			}else if(obj =='11'){
				return '天猫电子发票';
			}else if(obj =='12'){
				return '天猫纸质发票';
			}else if(obj =='21'){
				return 'o2o云推广电子发票';
			}else if(obj =='22'){
				return 'o2o云推广纸质发票';
			}
		} ,
		'ConvertInvoiceStatus':function(obj){
			if(obj=="1"){
				return '未开';
			}else if(obj=='2'){
				return '开票中（未向服务商提交）';
			}else if(obj=='3'){
				return '开票中（向服务商提交）';
			}else if(obj == '4'){
				return '服务商开票完成待回传';
			}else if(obj =='5' ){
				return '服务商开票失败';
			}else if(obj=='6'){
				return '纸质发票开票失败';
			}else if(obj=='7'){
				return '金额差异错误';
			}else if(obj=='8'){
				return 'pdf下载成功';
			}else if(obj=='9'){
				return '发票下载失败';
			}else if(obj=='10'){
				return 'prepare upload成功';
			}else if(obj=='11'){
				return '天猫预上传失败';
			}else if(obj=='12'){
				return '蓝票开取成功';
			}else if(obj=='13'){
				return '天猫上传异常';
			}else if(obj=='14'){
				return '冲红完成';
			}else if(obj=='15'){
				return '纸质发票成功';
			}else{
				return obj;
			}
		},
		'ConvertCashBackStatus':function(obj){
			if(obj == '0'){
				return '未导入';
			} 
			return '已导入';
		}   ,
		'ConvertOrderType':function(obj){
			if(obj == '1'){
				return '天猫';
			} else if(obj =='2'){
				return '京东';
			}else if(obj =='3'){
				return '官网';
			}else if(obj =='5'){
				return '英雄会';
			}else if(obj =='6'){
				return '村淘';
			}else if(obj =='7'){
				return '天猫企业采购';
			}else if(obj =='8'){
				return '经销商';
			}else if(obj =='13'){
				return '等级品销售';
			}
			return '未分类';
		} 
		
		
};


$(document).ready(function(){
	OrderPage.BindEvent();
});


